package com.du.spring.service;

import com.du.spring.dao.AccountDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author : DuJiabao
 * @Date : 2021/3/18 12:21
 * @Project : spring
 * @File : null.java
 * @Desc :
 */
@Service
@Transactional
public class AccountService{
  AccountDao accountDao;

  public int transfer(int fromId, int toId, BigDecimal money) {
    int res1 = accountDao.changeAccount(fromId, money.negate());
    //System.out.println(10 / 0);
    int res2 = accountDao.changeAccount(toId, money);
    if (res1 > 0 && res2 > 0)
      return 1;
    else
      return 0;
  }

  @Autowired
  public void setAccountDao(AccountDao accountDao) {
    this.accountDao = accountDao;
  }
}
